import MMUI.Checkbox;
import MMUI.Container;
import MMUI.MMUIPackage;
import MMUI.Option;
import MMUI.Widget;
import com.google.common.base.Objects;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.Resource.Factory.Registry;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.IterableExtensions;

@SuppressWarnings("all")
public class Generateur {
  public void main(final String[] args) {
    this.generateurHTML();
  }
  
  public CharSequence generateurHTML() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<html>");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("<head>");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("\"A form with HTML\"");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("</head>");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("<body>");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("<form>");
    _builder.newLine();
    _builder.append("\t\t\t");
    Container _container = this.getContainer("/");
    this.parseContainer(_container);
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("</form>");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("</body>");
    _builder.newLine();
    _builder.append("</html>");
    _builder.newLine();
    return _builder;
  }
  
  public Container getContainer(final String s) {
    ResourceSetImpl _resourceSetImpl = new ResourceSetImpl();
    ResourceSet resourceSet = _resourceSetImpl;
    Registry _resourceFactoryRegistry = resourceSet.getResourceFactoryRegistry();
    Map<String,Object> _extensionToFactoryMap = _resourceFactoryRegistry.getExtensionToFactoryMap();
    XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl();
    _extensionToFactoryMap.put(Registry.DEFAULT_EXTENSION, _xMIResourceFactoryImpl);
    MMUIPackage.eINSTANCE.eClass();
    URI _createURI = URI.createURI(s);
    Resource resource = resourceSet.getResource(_createURI, true);
    EList<EObject> _contents = resource.getContents();
    EObject _head = IterableExtensions.<EObject>head(_contents);
    Container container = ((Container) _head);
    return container;
  }
  
  public void parseContainer(final Container container) {
    EList<Widget> _widget = container.getWidget();
    Iterator<Widget> widgetIterator = _widget.iterator();
    boolean _hasNext = widgetIterator.hasNext();
    boolean _while = _hasNext;
    while (_while) {
      {
        Widget _next = widgetIterator.next();
        Widget widget = ((Widget) _next);
        Class<? extends Widget> _class = widget.getClass();
        boolean _equals = Objects.equal(_class, Checkbox.class);
        if (_equals) {
          this.getCheckbox(widget);
        } else {
          this.getRadioButton(widget);
        }
      }
      boolean _hasNext_1 = widgetIterator.hasNext();
      _while = _hasNext_1;
    }
  }
  
  public String getCheckbox(final Widget widget) {
    String _text = widget.getText();
    String result = (_text + "\n");
    EList<Option> _options = widget.getOptions();
    Iterator<Option> optionIterator = _options.iterator();
    boolean _hasNext = optionIterator.hasNext();
    boolean _while = _hasNext;
    while (_while) {
      String _plus = (result + "<input type=\'checkbox\' name=\'widgetCheckbox\' value=\'\'>");
      Option _next = optionIterator.next();
      String _plus_1 = (_plus + _next);
      result = _plus_1;
      boolean _hasNext_1 = optionIterator.hasNext();
      _while = _hasNext_1;
    }
    return result;
  }
  
  public String getRadioButton(final Widget widget) {
    String _text = widget.getText();
    String result = (_text + "\n");
    EList<Option> _options = widget.getOptions();
    Iterator<Option> optionIterator = _options.iterator();
    boolean _hasNext = optionIterator.hasNext();
    boolean _while = _hasNext;
    while (_while) {
      String _plus = (result + "<input type=\'radio\' name=\'widgetRadio\' value=\'\'>");
      Option _next = optionIterator.next();
      String _plus_1 = (_plus + _next);
      result = _plus_1;
      boolean _hasNext_1 = optionIterator.hasNext();
      _while = _hasNext_1;
    }
    return result;
  }
}
